<!DOCTYPE HTML>
<html>
   <head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<title>知果汇</title>
		<link href="_CSS_/bootstrap.min.css" rel="stylesheet">
		<link href="_CSS_/simple-line-icons.css" rel="stylesheet">
		<link href="_CSS_/font-awesome.min.css" rel="stylesheet">
		<link href="_CSS_/jasny-bootstrap.min.css" rel="stylesheet">
		<link rel="stylesheet" href="_CSS_/nanoscroller.css">
		<link href="_CSS_/style.css" rel="stylesheet">
		<link rel="stylesheet" type="text/css" href="_CSS_/jquery-ui.css">
		<!--[if lt IE 9]>
		  <script src="js/html5shiv.min.js"></script>
		  <script src="js/respond.min.js"></script>
		<![endif]-->
		<style type="text/css">
		    body{background-color: #ffffff;min-width: 500px;}
			.row{margin-left: 0px;margin-right: 0px;min-width: 500px;}
			.radio-box{display:inline-block;width: 64px;}
			.formControls{padding-right:50px; position: relative;}
			.textarea {height: 100px;resize: none;font-size: 14px;padding: 4px;}
            .textarea-numberbar {position: absolute;right: 70px;bottom: 5px;z-index: 1;margin-bottom: 0;}
		</style>
    </head>
	<body>
	<article class="page-container">
		<form class="form form-horizontal" id="form-admin-add">
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">名称：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<input type="text" class="input-text" value="" placeholder="" id="systemname" name="systemname">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">所属模块：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<span class="select-box">
						<p id="tabname" >
						</p>
					</span> 
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">上级字典：</label>
				<div class="formControls col-xs-8 col-sm-9">
					<span class="select-box">
						<p id="fieldname">
						</p>
					</span> 
				</div>
			</div>
			<div class="row cl">
				<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
					<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
					<button class="btn btn-cancel radius" id="btn-cancel" style="color: #ffffff;background-color: #a0a0a0;width: 72px;">取消</button>
				</div>
			</div>
			<input type="hidden" tid="" id="" class="info" name="">
			<input type="hidden" id="add_id" value="{$id}" name="">
			<input type="hidden" id="add_tag" value="{$tag}" name="">
		</form>
	</article>

    <script src="_JS_/jquery.min.js"></script>
    <script src="_JS_/bootstrap.min.js"></script>
    <script src="_JS_/jasny-bootstrap.min.js"></script>
    <script src="_JS_/jquery.slimscroll.min.js"></script>
    <script src="_JS_/jquery.nanoscroller.min.js"></script>
    <script src="_JS_/metismenu.min.js"></script>
    <script src="_JS_/float-custom.js"></script>
    <script type="text/javascript" src="_JS_/layer/layer.js"></script>
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/jquery.validate.min.js"></script> 
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/validate-methods.js"></script> 
    <script type="text/javascript" src="_JS_/jquery.validation/1.14.0/messages_zh.min.js"></script> 

	<script type="text/javascript">
	
	var id = $('#add_id').val();
	/*textarea 字数限制*/
	function textarealength(obj,maxlength){
		var v = $(obj).val();
		var l = v.length;
		if( l > maxlength){
			v = v.substring(0,maxlength);
			$(obj).val(v);
		}
		$(obj).parent().find(".textarea-length").text(v.length);
	}
	$(function(){
		$("#form-admin-add").validate({
			rules:{
				systemname:{
					required:true,
					minlength:1,
					maxlength:16
				},
			},
			onkeyup:false,
			focusCleanup:true,
			success:"valid",
			submitHandler:function(form){ 
				var name=$("#systemname").val();
				var add_id=$(".info").attr('id');
				var add_tid=$(".info").attr('tid');
				var add_tag=$("#add_tag").val();
				$.ajax({ 
			        type: "get", 
			        url: "{:url('api/Dictionary/add')}",
			        dataType: 'jsonp',
                    jsonp:'callback',
			        data:{'name':name,'pid':add_id,'tid':add_tid,'tag':add_tag},
			        success: function (msg) {
			            if(msg.code == 200){ 
			            	layer.msg(msg.message,{icon:1,time:1000},function(){
								parent.window.location.reload();
							});
			            	/*var index = parent.layer.getFrameIndex(window.name);
							//parent.getlist(1);
							parent.layer.close(index);*/
			            }
			            if(msg.code==1000){
			                layer.msg('添加失败!',{icon:2,time:1000});
			            }
			        }
			    });
			}

			
		});

		$("#btn-cancel").click(function(){
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		});

		/*获取上级目录和所属模块信息*/
		$.ajax({ 
	        type: "get", 
	        url: "{:url('api/Dictionary/get_info')}",
	        dataType: 'jsonp',
            jsonp:'callback',
	        data:{'id':id},
	        success: function (msg) {
	            if(msg.code == 200){ 
	            	var index = parent.layer.getFrameIndex(window.name);
					//parent.getlist(1);
					var tabname = msg['data']['t_name'];
					var fieldname = msg['data']['name'];
					var add_id = msg['data']['id'];
					var add_tid = msg['data']['tid'];
					$('#tabname').html(tabname);
					$('#fieldname').html(fieldname);
					$('.info').attr('tid',add_tid);
					$('.info').attr('id',add_id);
					// parent.layer.close(index);
	            }
	            if(msg.code==1000){
	                layer.msg('获取失败!',{icon:2,time:1000});
	            }
	        }
	    });
	});
	
	</script> 
</body>
</html>